package org.dbview.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.dbview.dao.IViewDictionaryMapper;
import org.dbview.model.ViewDictionary;
import org.dbview.model.ViewdictPageItem;
import org.dbview.service.IViewDictionaryService;
import org.springframework.beans.factory.annotation.Autowired;

public class ViewDictionaryServiceImpl implements IViewDictionaryService {
	private static Logger logger = Logger.getLogger(ViewDictionaryServiceImpl.class);
	
	@Autowired
	private IViewDictionaryMapper viewDictionaryMapper;

	@Override
	public ViewdictPageItem getViewByModuleAndTable(ViewdictPageItem viewdictPageItem) {
		try {
			viewdictPageItem.setViewList(viewDictionaryMapper
					.findViewByModulAndTable(viewdictPageItem));
			viewdictPageItem.getPage()
					.setCount(
							viewDictionaryMapper
									.countByModulAndTable(viewdictPageItem));
			return viewdictPageItem;
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return null;
		}
	}

	@Override
	public List<ViewDictionary> getColumnByTable(String tableName) {
		try {
			return viewDictionaryMapper.findColumnByTable(tableName);
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return null;
		}
	}

	@Override
	public List<ViewDictionary> getAllTable() {
		try {
			return viewDictionaryMapper.findAllTable();
		} catch (Exception e) {
			logger.error(e.getMessage(), e);
			return null;
		}
	}

	@Override
	public List<ViewDictionary> findViewByTable(String tableName) {
		return viewDictionaryMapper.findViewByTable(tableName);
	}

	@Override
	public List<ViewDictionary> findViewByTableAndColumn(String tableName,
			String columnName) {
		Map<String, String> paramsMap = new HashMap<String, String>();
		paramsMap.put("tableName", tableName);
		paramsMap.put("columnName", columnName);
		return viewDictionaryMapper.findViewByTableAndColumn(paramsMap);
	}

}
